/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.zimbra.common.calendar.ZCalendar.ICalTok;
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Group;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.index.SearchParams.ExpandResults;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import com.zimbra.cs.service.mail.ToXML.EmailType;
/*     */ import com.zimbra.soap.mail.message.CreateAppointmentRequest;
/*     */ import com.zimbra.soap.mail.message.CreateAppointmentResponse;
/*     */ import com.zimbra.soap.mail.message.GetMsgRequest;
/*     */ import com.zimbra.soap.mail.message.GetMsgResponse;
/*     */ import com.zimbra.soap.mail.message.SearchConvRequest;
/*     */ import com.zimbra.soap.mail.message.SearchConvResponse;
/*     */ import com.zimbra.soap.mail.message.SearchRequest;
/*     */ import com.zimbra.soap.mail.message.SearchResponse;
/*     */ import com.zimbra.soap.mail.message.SendMsgRequest;
/*     */ import com.zimbra.soap.mail.message.SendMsgResponse;
/*     */ import com.zimbra.soap.mail.type.CalOrganizer;
/*     */ import com.zimbra.soap.mail.type.CalendarAttendee;
/*     */ import com.zimbra.soap.mail.type.CalendarAttendeeWithGroupInfo;
/*     */ import com.zimbra.soap.mail.type.DtTimeInfo;
/*     */ import com.zimbra.soap.mail.type.EmailAddrInfo;
/*     */ import com.zimbra.soap.mail.type.EmailInfo;
/*     */ import com.zimbra.soap.mail.type.InvitationInfo;
/*     */ import com.zimbra.soap.mail.type.InviteComponent;
/*     */ import com.zimbra.soap.mail.type.InviteComponentWithGroupInfo;
/*     */ import com.zimbra.soap.mail.type.InviteWithGroupInfo;
/*     */ import com.zimbra.soap.mail.type.MessageHitInfo;
/*     */ import com.zimbra.soap.mail.type.MimePartInfo;
/*     */ import com.zimbra.soap.mail.type.Msg;
/*     */ import com.zimbra.soap.mail.type.MsgSpec;
/*     */ import com.zimbra.soap.mail.type.MsgToSend;
/*     */ import com.zimbra.soap.mail.type.MsgWithGroupInfo;
/*     */ import com.zimbra.soap.type.SearchHit;
/*     */ import java.util.List;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestExpandGroupInfo
/*     */   extends SoapTest
/*     */ {
/*     */   private static SoapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   private static Account acct;
/*     */   private static Group group;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  75 */     provUtil = new SoapProvTestUtil();
/*  76 */     prov = provUtil.getProv();
/*  77 */     domain = provUtil.createDomain(baseDomainName());
/*     */     
/*  79 */     acct = provUtil.createAccount("acct", domain);
/*  80 */     group = provUtil.createGroup("group", domain, true);
/*     */     
/*  82 */     prov.addGroupMembers(group, new String[] { acct.getName() });
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup()
/*     */     throws Exception
/*     */   {
/*  89 */     if (acct != null) {
/*  90 */       provUtil.deleteAccount(acct);
/*     */     }
/*     */     
/*  93 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private void sendMsg(Account authAcct, String toAddress, String subject, String content) throws Exception
/*     */   {
/*  98 */     SoapTransport transport = authUser(authAcct.getName());
/*     */     
/* 100 */     MsgToSend msg = new MsgToSend();
/*     */     
/* 102 */     EmailAddrInfo toAddr = new EmailAddrInfo(toAddress);
/* 103 */     toAddr.setAddressType(ToXML.EmailType.TO.toString());
/* 104 */     msg.addEmailAddress(toAddr);
/*     */     
/* 106 */     msg.setSubject(subject);
/*     */     
/* 108 */     MimePartInfo mp = new MimePartInfo();
/* 109 */     mp.setContentType("text/plain");
/* 110 */     mp.setContent(content);
/* 111 */     msg.setMimePart(mp);
/*     */     
/* 113 */     SendMsgRequest req = new SendMsgRequest();
/* 114 */     req.setMsg(msg);
/*     */     
/* 116 */     SendMsgResponse resp = (SendMsgResponse)invokeJaxb(transport, req);
/*     */   }
/*     */   
/*     */   private String createAppt(Account authAcct, String toAddress, String subject, String content) throws Exception
/*     */   {
/* 121 */     SoapTransport transport = authUser(authAcct.getName());
/*     */     
/* 123 */     Msg msg = new Msg();
/*     */     
/* 125 */     EmailAddrInfo toAddr = new EmailAddrInfo(toAddress);
/* 126 */     toAddr.setAddressType(ToXML.EmailType.TO.toString());
/* 127 */     msg.addEmailAddress(toAddr);
/*     */     
/* 129 */     msg.setSubject(subject);
/*     */     
/* 131 */     MimePartInfo mp = new MimePartInfo();
/* 132 */     mp.setContentType("multipart/alternative");
/* 133 */     MimePartInfo mpSub = new MimePartInfo();
/* 134 */     mpSub.setContent(content);
/* 135 */     mp.addMimePart(mpSub);
/* 136 */     msg.setMimePart(mp);
/*     */     
/* 138 */     InvitationInfo invite = new InvitationInfo();
/* 139 */     InviteComponent invComp = new InviteComponent(ZCalendar.ICalTok.REQUEST.name(), 0, false);
/* 140 */     CalOrganizer organizer = new CalOrganizer();
/* 141 */     organizer.setAddress(authAcct.getName());
/* 142 */     CalendarAttendee attendee = new CalendarAttendee();
/* 143 */     attendee.setAddress(toAddress);
/* 144 */     invComp.setOrganizer(organizer);
/* 145 */     invComp.addAttendee(attendee);
/* 146 */     invComp.setDtStart(new DtTimeInfo("20120101"));
/* 147 */     invComp.setDtEnd(new DtTimeInfo("20120102"));
/* 148 */     invite.setInviteComponent(invComp);
/* 149 */     msg.setInvite(invite);
/*     */     
/* 151 */     CreateAppointmentRequest req = new CreateAppointmentRequest();
/* 152 */     req.setMsg(msg);
/* 153 */     CreateAppointmentResponse resp = (CreateAppointmentResponse)invokeJaxb(transport, req);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 160 */     String invId = resp.getCalInvId();
/* 161 */     return invId;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private void verifyGroupInfo(MessageHitInfo hit, Boolean expectedIsGroup, Boolean expectedCanExpand)
/*     */   {
/* 211 */     List<EmailInfo> emails = hit.getEmails();
/* 212 */     for (EmailInfo emailInfo : emails) {
/* 213 */       String addrType = emailInfo.getAddressType();
/* 214 */       if (ToXML.EmailType.TO.toString().equals(addrType)) {
/* 215 */         String addr = emailInfo.getAddress();
/* 216 */         Boolean isGroup = emailInfo.getGroup();
/* 217 */         Boolean canExpandGroupMembers = emailInfo.getCanExpandGroupMembers();
/* 218 */         Assert.assertEquals(expectedIsGroup, isGroup);
/* 219 */         Assert.assertEquals(canExpandGroupMembers, expectedCanExpand);
/* 220 */         return;
/*     */       }
/*     */     }
/*     */     
/* 224 */     Assert.fail();
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void searchConversation() throws Exception
/*     */   {
/* 230 */     String SUBJECT = getTestName();
/* 231 */     sendMsg(acct, group.getName(), SUBJECT, "blah");
/*     */     
/* 233 */     SoapTransport transport = authUser(acct.getName());
/*     */     
/* 235 */     SearchRequest searchReq = new SearchRequest();
/* 236 */     searchReq.setSearchTypes(MailItem.Type.CONVERSATION.toString());
/* 237 */     searchReq.setQuery(String.format("in:inbox and subject:%s", new Object[] { SUBJECT }));
/* 238 */     SearchResponse searchResp = (SearchResponse)invokeJaxb(transport, searchReq);
/* 239 */     List<SearchHit> searchHits = searchResp.getSearchHits();
/* 240 */     Assert.assertEquals(1L, searchHits.size());
/*     */     
/* 242 */     SearchHit searchHit = (SearchHit)searchHits.get(0);
/* 243 */     String convId = searchHit.getId();
/*     */     
/* 245 */     SearchConvRequest searchConvReq = new SearchConvRequest(convId);
/* 246 */     searchConvReq.setNeedCanExpand(Boolean.TRUE);
/* 247 */     searchConvReq.setFetch(SearchParams.ExpandResults.ALL.toString());
/* 248 */     SearchConvResponse searchConvResp = (SearchConvResponse)invokeJaxb(transport, searchConvReq);
/* 249 */     List<MessageHitInfo> hits = searchConvResp.getMessages();
/* 250 */     Assert.assertEquals(2L, hits.size());
/* 251 */     verifyGroupInfo((MessageHitInfo)hits.get(0), Boolean.TRUE, Boolean.TRUE);
/* 252 */     verifyGroupInfo((MessageHitInfo)hits.get(1), Boolean.TRUE, Boolean.TRUE);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void search() throws Exception
/*     */   {
/* 258 */     String SUBJECT = getTestName();
/* 259 */     sendMsg(acct, group.getName(), SUBJECT, "blah");
/*     */     
/* 261 */     SoapTransport transport = authUser(acct.getName());
/*     */     
/* 263 */     SearchRequest searchReq = new SearchRequest();
/* 264 */     searchReq.setSearchTypes(MailItem.Type.MESSAGE.toString());
/* 265 */     searchReq.setQuery(String.format("in:inbox and subject:%s", new Object[] { SUBJECT }));
/* 266 */     searchReq.setFetch(SearchParams.ExpandResults.ALL.toString());
/* 267 */     SearchResponse searchResp = (SearchResponse)invokeJaxb(transport, searchReq);
/* 268 */     List<SearchHit> searchHits = searchResp.getSearchHits();
/* 269 */     Assert.assertEquals(1L, searchHits.size());
/*     */     
/* 271 */     verifyGroupInfo((MessageHitInfo)searchHits.get(0), null, null);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 276 */     searchReq.setNeedCanExpand(Boolean.TRUE);
/* 277 */     searchResp = (SearchResponse)invokeJaxb(transport, searchReq);
/* 278 */     searchHits = searchResp.getSearchHits();
/* 279 */     Assert.assertEquals(1L, searchHits.size());
/*     */     
/* 281 */     verifyGroupInfo((MessageHitInfo)searchHits.get(0), Boolean.TRUE, Boolean.TRUE);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getMsg() throws Exception {
/* 286 */     String SUBJECT = getTestName();
/* 287 */     String msgId = createAppt(acct, group.getName(), SUBJECT, "blah");
/*     */     
/* 289 */     SoapTransport transport = authUser(acct.getName());
/*     */     
/* 291 */     MsgSpec msgSpec = new MsgSpec(msgId);
/* 292 */     msgSpec.setNeedCanExpand(Boolean.TRUE);
/* 293 */     GetMsgRequest req = new GetMsgRequest(msgSpec);
/* 294 */     GetMsgResponse resp = (GetMsgResponse)invokeJaxb(transport, req);
/*     */     
/* 296 */     MsgWithGroupInfo msg = resp.getMsg();
/* 297 */     InviteWithGroupInfo invite = msg.getInvite();
/* 298 */     List<InviteComponentWithGroupInfo> invComps = invite.getInviteComponents();
/*     */     
/* 300 */     for (InviteComponentWithGroupInfo invComp : invComps) {
/* 301 */       List<CalendarAttendeeWithGroupInfo> attendees = invComp.getAttendees();
/* 302 */       for (CalendarAttendeeWithGroupInfo attendee : attendees) {
/* 303 */         Boolean isGroup = attendee.getGroup();
/* 304 */         Boolean canExpandGroupMembers = attendee.getCanExpandGroupMembers();
/* 305 */         Assert.assertTrue(isGroup.booleanValue());
/* 306 */         Assert.assertTrue(canExpandGroupMembers.booleanValue());
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/TestExpandGroupInfo.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */